Skip to content

docs: describe idempotent consumption without overstating its guarantees - #6

Merged
muhammetsafak merged 2 commits into
mainfrom
docs/idempotency-honest-guarantees
Nov 23, 2026
Merged

muhammetsafak merged 2 commits into
mainfrom
docs/idempotency-honest-guarantees

Conversation

@muhammetsafak

Copy link
Copy Markdown
Contributor

What

The idempotency page and the README section described a guarantee the dispatcher does not give. Dispatcher::runHandler() treats a claimed-but-not-recorded key like a recorded one, so the duplicate is acknowledged and discarded. This rewrites the docs to say what happens today (no source change):

  • A worker that claims a key and dies inside the handler loses the message when the redelivery arrives before the lease lapses. With the defaults (leaseSeconds: 300, PdoTransport retryAfter: 90) it always does; on RabbitMQ a closed connection redelivers at once.
  • A worker that dies after the handler but before remember() causes a second run once the lease lapses, so "at most once" is gone.
  • A failed attempt can lose its retry: a duplicate dropped while the first handler is still running deletes the PDO row, and the first handler's release() then updates nothing.
  • How to pick leaseSeconds: above the slowest handler, below the transport's redelivery time, with a per-transport table (PDO, Redis, RabbitMQ). 0 means no expiry, not no lease.
  • keyResolver example: scope the key by URN and return a string (a different message type for the same order was discarded as a duplicate; an int id was silently ignored).
  • A message without a trace_id is dead-lettered by the envelope validator before deduplication, so the "processed without deduplication" sentence is removed.
  • How a PDO store must free an expired lease, otherwise every redelivery is discarded.
  • at-least-once pages (FAQ, Core Concepts, Retries, Transport-PDO, Troubleshooting) no longer present deduplication as a replacement for an idempotent handler; job.dropped is documented for duplicates.

Verification

The three loss and double-run cases were reproduced end to end with a real PdoTransport (SQLite file), a shared store with a lease and worker processes killed with SIGKILL; the shorter-lease case recovers. wiki-sync.sh --check docs passes.

The dispatcher behaviour itself (the in-flight claim being dropped) is not changed here and is left for a separate decision.

An in-flight claim is treated like a recorded key, so a redelivery that
arrives while a dead worker's claim is held is acknowledged and discarded.
Document that loss window, the double run after a crash before remember(),
and how leaseSeconds relates to each transport's redelivery time.

Also drop the at-most-once and no-message-is-lost wording, scope the
keyResolver example by URN and return a string, correct the claim about
messages without an identity, and explain how a PDO store frees an expired
lease.
@muhammetsafak
muhammetsafak merged commit 1146631 into main Nov 23, 2026
10 checks passed
@muhammetsafak
muhammetsafak deleted the docs/idempotency-honest-guarantees branch November 23, 2026 07:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant